#ifndef TABELLAICONE_H
#define TABELLAICONE_H


#include "strutturaicone.h"
#include "ModelSwap.h"
#include "previewdialog.h"
#include "textprinter.h"




class AlphaDelegate : public QItemDelegate
{
    Q_OBJECT
public:
    AlphaDelegate(QObject *parent = 0 , QStringList external = QStringList());
    QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &, 
    const QModelIndex &index) const;   //////  15
    void setEditorData(QWidget *editor, const QModelIndex &index) const;  ////  59
    void setModelData(QWidget *editor, QAbstractItemModel *model,
    const QModelIndex &index) const;   //////  76
    QStringList External_Name;
private slots:
    void commitAndCloseEditor();   ///// 52
};


#include <QDomDocument>

//
class TabellaIcone : public QTableWidget
{
     Q_OBJECT
//
public:
 TabellaIcone( QWidget * parent = 0 );
 void OpenFromStreamString( const QString data );
 QString SaveString();
 bool unsaved;
protected:
  void closeEvent( QCloseEvent* e );
  void contextMenuEvent ( QContextMenuEvent * e );
private:
 QSettings setter;
  QAction *ActionswapIcon;
 QMap<int,int> linenummers;
 QMap<int,IcoLine> Updates;
 bool onloading;
 void FileOpener( const QString fixfile );
 QDateTime created;
 QMap<int,int> traduzioneNumero;
 void Parsefile( const QString fullFileName );
 void WrittelnLine( IcoLine Iconas , const int line );
 QList<QTableWidgetItem *> selector( const int riga );
signals:
     void SaveAll();
public slots:
   void UpdateFromFiles();
   void Esportapicweb_color();
   void Esportapicweb_bn();
   void ExportAsFile();
   void ImportFromFile();
   void NewDataSet( const int riga , const int linea );
   void LoadFromResource();
   void PrintItems();
   void OtherIconSet();

};




class IconeAttributi : public QDialog
{
    Q_OBJECT
//
public:
 IconeAttributi( QWidget * parent = 0 )
{
    setWindowFlags ( Qt::Window );
    resize(900, 600);
    setWindowTitle (tr("Attributi Case / Hotel / Agriturismo / Ostelli ")); 
    gridLayout = new QGridLayout(this);
    gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
    hboxLayout = new QHBoxLayout();
    hboxLayout->setObjectName(QString::fromUtf8("hboxLayout"));
    pushButton_4 = new QPushButton(this);
    pushButton_4->setObjectName(QString::fromUtf8("pushButton_4"));
    hboxLayout->addWidget(pushButton_4);
    pushButton_5 = new QPushButton(this);
    pushButton_5->setObjectName(QString::fromUtf8("pushButton_5"));
    hboxLayout->addWidget(pushButton_5);
    pushButton_2 = new QPushButton(this);
    pushButton_2->setObjectName(QString::fromUtf8("pushButton_2"));
    hboxLayout->addWidget(pushButton_2);
    spacerItem = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
    hboxLayout->addItem(spacerItem);
    pushButton = new QPushButton(this);
    pushButton->setObjectName(QString::fromUtf8("pushButton"));
    hboxLayout->addWidget(pushButton);
    pushButton_3 = new QPushButton(this);
    pushButton_3->setObjectName(QString::fromUtf8("pushButton_3"));
    hboxLayout->addWidget(pushButton_3);
    gridLayout->addLayout(hboxLayout, 0, 0, 1, 1);
    table = new TabellaIcone(this);
    gridLayout->addWidget(table, 1, 0, 1, 1);
    pushButton_4->setText(QApplication::translate("this", "Esporta icone a colori web", 0, QApplication::UnicodeUTF8));
    pushButton_5->setText(QApplication::translate("this", "Esporta icone B/N web", 0, QApplication::UnicodeUTF8));
    pushButton_2->setText(QApplication::translate("this", "Salva su file", 0, QApplication::UnicodeUTF8));
    pushButton->setText(QApplication::translate("this", "Salva in db", 0, QApplication::UnicodeUTF8));
    pushButton_3->setText(QApplication::translate("this", "Chiudi", 0, QApplication::UnicodeUTF8));
    connect(pushButton_4, SIGNAL(clicked()),table, SLOT(Esportapicweb_color()));
    connect(pushButton_2, SIGNAL(clicked()),table, SLOT(ExportAsFile()));
    connect(pushButton_5, SIGNAL(clicked()),table, SLOT(Esportapicweb_bn()));
    connect(pushButton_3, SIGNAL(clicked()),this, SLOT(accept()));
    
    connect(table, SIGNAL(SaveAll()),this, SLOT(SaveDB()));
    
    ////////pushButton->setDisabled (true );
    connect(pushButton, SIGNAL(clicked()),this, SLOT(SaveDB()));
    
 
}
QString Streamend() 
{
    return stream;
}

    QGridLayout *gridLayout;
    QHBoxLayout *hboxLayout;
    QPushButton *pushButton_4;
    QPushButton *pushButton_5;
    QPushButton *pushButton_2;
    QSpacerItem *spacerItem;
    QPushButton *pushButton;
    QPushButton *pushButton_3;
    TabellaIcone *table;
    QString stream;
protected:
  
void closeEvent( QCloseEvent *  e )
{
    
    if (table->unsaved) {
        
      QString msgDB =tr("Vuoi salvare i dati modificati?");
      int removeyes = QMessageBox::question(this, tr("Prego confermare!"),msgDB,
                                                            tr("&Si"), tr("&No"),
                                                             QString(),8888,9999);
			if (removeyes == 0) {
          SaveDB();
      }
    }
    
e->accept();
}

private:
signals:
public slots:
    void SaveDB()
{
    stream = table->SaveString();
    accept();
}

};
















//
#endif // TABELLAICONE_H

